/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CreateTable;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author tashiba
 */
public class CreateTableGolonganDarah {
    public static void main(String[] args) {

        try {
            try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(CreateTableUser.class.getName()).log(Level.SEVERE, null, ex);
            }
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/pti", "root", "115314034");


            System.out.println("Koneksi is OK");
            Statement statement = conn.createStatement();
            String golDarah = " CREATE TABLE GOLONGANDARAH(IDGD VARCHAR(10) NOT NULL,"
                    + "NAMAGD VARCHAR(5),"
                    + "CONSTRAINT GOLONGANDARAH_PK PRIMARY KEY(IDGD));";

            statement.executeUpdate(golDarah);
            System.out.println("Tabel GOLONGAN DARAH Created");
            
            ResultSet rs = null;
            PreparedStatement pst = null;

            String sql = "insert into golongandarah (idgd,namagd)"
                    + "values ('A','A'),('AB','AB'),('B','B'),('O','O')";

            pst = conn.prepareStatement(sql);
            pst.execute();
            System.out.println("data berhasil ditambahkan");
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
        }
    }
}
